/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.amazon.main;

import com.amazon.node.Node;
import com.amazon.node.Number;
import com.amazon.node.Operator;
import com.amazon.tree.Tree;
/**
 *
 * @author nms
 */
public class BinaryTreeExpressionSolver {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws InstantiationException {
        // TODO code application logic here
        System.out.println("Evaluating (5+6)*5");
        Tree t = new Tree("*",new Operator("+",new Number("5"),new Number("6")), new Number("5"));
        System.out.println("Result: "+t.solveTree());
        System.out.println("=============================================");
        
        
        System.out.println("Evaluating ((5*6)+6)+5");
        Node InnerOperatorNode =new Operator("*",new Number("5"),new Number("6"));
        Tree t1 = new Tree("+",new Operator("+",InnerOperatorNode,new Number("6")), new Number("5"));
        System.out.println("Result: "+t1.solveTree());
        System.out.println("Evaluating inner bracket or node (5*6) of expression ((5*6)+6)+5");
        System.out.println("Result: "+InnerOperatorNode.evaluate());
        System.out.println("=============================================");
        
        
        System.out.println("Evaluating ((5*6)*6)*5");
        Node InnerOperatorNode1 = new Operator("*",new Operator("*",new Number("5"),new Number("6")),new Number("6"));
        Tree t2 = new Tree("*",InnerOperatorNode1, new Number("5"));
        System.out.println("Result: "+t2.solveTree());
        System.out.println("Evaluating inner bracket or node ((5*6)*6) of expression ((5*6)*6)*5");
        System.out.println("Result: "+InnerOperatorNode1.evaluate());
        System.out.println("=============================================");
        
        System.out.println("Evaluating ((11+6)+6)*5");
        Node InnerNumberNode = new Number("11");
        Tree t4 = new Tree("*",new Operator("+",new Operator("+",InnerNumberNode,new Number("6")),new Number("6")), new Number("5"));
        System.out.println("Result: "+t4.solveTree());
        System.out.println("Evaluating inner node 11 of ((11+6)+6)*5 which is actually a number");
        System.out.println("Result: "+InnerNumberNode.evaluate());
        System.out.println("=============================================");
        
        
//        System.out.println(op.solve());
    }
}
